<?php
class listController extends commonController{
	public function __construct(){
		parent::__construct();
		$this->navigation();
	}
	/*
	 * 列表页
	 */
	 public function index(){
		$cid=(int)$_GET['cid'];
		$sonData = M('wenda')->query("SELECT * FROM hd_category WHERE pid ='{$cid}' ");
		//如果下面有子分类
		if(empty($sonData)){
			$pid=M('hd_category')->query("SELECT pid FROM hd_category WHERE cid = '{$cid}'");
			$pid =$pid[0]['pid'];
			$sonData = M('hd_category')->query("SELECT * FROM hd_category WHERE pid='{$pid}'");

		}
		$this->assign('sonData',$sonData);
		/*
		 * tab切换处理
		 */
		$tab = isset($_GET['tab'])?(int)$_GET['tab']:0;
		switch($tab){
			case 1:
				$sql = "SELECT * FROM hd_ask AS a JOIN hd_category AS c ON a.cid = c.cid WHERE solve = 0";
				break;
			case 2:
				$sql = "SELECT * FROM hd_ask AS a JOIN hd_category AS c ON a.cid = c.cid WHERE solve = 1";
				break;
			case 3:
				$sql = "SELECT * FROM hd_ask AS a JOIN hd_category AS c ON a.cid = c.cid WHERE reward >= 20";
				break;
			case 4:
				$sql = "SELECT * FROM hd_ask AS a JOIN hd_category AS c ON a.cid = c.cid WHERE answer = 0 ";
				break;
		}
		//
		$sql = "SELECT * FROM hd_ask AS a JOIN hd_category AS c ON a.cid = c.cid WHERE solve = 0";

		$sql .= " and a.cid = {$cid}";

		$askData = M('hd_ask') ->query($sql);
		
		$this->assign('askData',$askData);
//		var_dump($askData);
		
		$this->topCate();
		$this->display();
		$this->navigation();
	 }

	/**
	 * 获得父级
	 */
	private function getFather($data,$cid){
		$temp = array();
		if($cid==0){
			return $temp;
		}
		foreach ($data as $v) {
			if($v['cid'] == $cid){
				$temp[] = $v;
				$temp = array_merge($temp,$this->getFather($data, $v['pid']));
			}
		}
		return $temp;
	}
	
} 